package com.captain.special.二叉树.简单;

import com.captain.leetcode.TreeNode;

/**
 * Des:
 *
 * @author XL
 * @Date 2022/5/9 10:24
 */
public class 递增顺序搜索树897 {
    TreeNode curAns;
    TreeNode ans;

    public TreeNode increasingBST(TreeNode root) {
        recur(root);
        return ans;
    }

    public void recur(TreeNode node) {
        if (node == null) return;
        recur(node.left);
        int val = node.val;
        if (curAns == null) {
            ans = new TreeNode(val);
            curAns = ans;
        } else {
            curAns.left = null;
            TreeNode treeNode = new TreeNode(val);
            curAns.right = treeNode;
            curAns = treeNode;
        }
        recur(node.right);
    }
}
